/*
 * @Author: Warren
 * @Date: 2025-02-28 08:49:18
 * @LastEditors: Warren
 * @LastEditTime: 2025-07-23 22:04:29
 * @FilePath: /nest-web/src/modules/user/user.service.ts
 * @Description: 请填写文件说明
 */
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { User } from 'src/entities/user.entity';
import { Repository } from 'typeorm';

@Injectable()
export class UserService {
    constructor(
        @InjectRepository(User)
        private userRepository: Repository<User>
    ) {

    }

    create() {
        const user = new User()
        user.username = 'insert'
        user.password = 'pasw'
        console.log('🚀 ~ UserService ~ create ~ user:', user)

        this.userRepository.save(user)
    }

    async findAll(): Promise<User[]> {
        return this.userRepository.find();
    }

    /**
     * @description: 通过 用户名 查询
     * @param {string} username
     * @return {User} User
     */    
    async findOne(username: string): Promise<User> {
        return this.userRepository.findOneBy({ username });
    }

    /**
     * @description: 通过 用户ID 查询
     * @param {string} id
     * @return {User} User
     */    
    async findOneId(id: number): Promise<User> {
        return this.userRepository.findOneBy({ id });
    }
}